#pragma once

class CEX FilePath
{

	FilePath(){}

public:

	static String getMountPoint(const String& path)
	{
		int p = path.pos(":");

		if(p<=0 || path[p+1]!='/')
			throw Error("Invalid path");

		return path.left(p);
	}

	static String getPath(const String& path,bool includeFilename = false)
	{
		int p1 = path.pos(":");
		
		if(p1<=0 || path[p1+1]!='/')
			throw Error("Invalid path");

		p1++;

		if(includeFilename)
			return path.sub(p1);

		int p2 = path.pos("/",path.getLen()-1,true);

		return path.sub(p1,p2-p1+1);

	}

	static String getFilename(const String& path,bool includeExtension = true)
	{
		int p1 = path.pos(":");
		
		if(p1<=0 || path[p1+1]!='/')
			throw Error("Invalid path");

		p1 = path.pos("/",path.getLen()-1,true)+1;

		if(includeExtension)
			return path.sub(p1);

		int p2 = path.pos(".",p1);

		if(p2==-1)
			return path.sub(p1);

		return path.sub(p1,p2-p1);
	
	}

	static String getExtension(const String& path)
	{
		int p1 = path.pos(":");
		
		if(p1<=0 || path[p1+1]!='/')
			throw Error("Invalid path");

		p1 = path.pos("/",path.getLen()-1,true)+1;
		int p2 = path.pos(".",p1);

		if(p2==-1)
			return "";

		return path.sub(p2);
	}

};
